package com.google.code.ptrends.locators.implementations;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.lang.StringUtils;

import com.google.code.ptrends.locators.Locator;

/**
 * 
 * @author Daniel
 * 
 */
public class FileLocator implements Locator {

	private String sourceLocation;
	private FileInputStream stream;

	public FileLocator(final String sourceLocation) {
		if (StringUtils.isBlank(sourceLocation)) {
			throw new IllegalArgumentException("Illegal blank source location");
		}
		this.sourceLocation = sourceLocation;
		this.stream = null;
	}

	@Override
	public InputStream getStream() throws IOException {
		this.stream = new FileInputStream(sourceLocation);
		return this.stream;
	}

	@Override
	public void close() {
		try {
			if (stream != null)
				this.stream.close();
		} catch (IOException e) {
			// e.printStackTrace();
		}
	}

}
